/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package tetris.model;

import java.awt.Color;
import java.awt.Graphics;

public abstract class Piece {
    protected int numberOfRotations;
    protected int currentRotation = 0;
    protected boolean active = false;
    protected Color color;
    protected Rotation[] rotations;
    protected int x, y;
    protected int highestY;

    public Piece(int numberOfRotations, Color col){
        this.numberOfRotations = numberOfRotations;
        this.color = col;
        this.rotations = new Rotation[this.numberOfRotations];
    }

    public void paintPiece(int x, int y, Graphics g){
        this.rotations[currentRotation].paint(x, y, this.color, g);
    }

    public Color getColor(){
        return this.color;
    }
    
    public void setActive(int x, int y){
        this.x = x;
        this.y = y;
        this.active = true;
    }

    public void setXY(int x, int y){
        this.x = x;
        this.y = y;
    }

    public int getX(){
        return this.x;
    }

    public int getY(){
        return this.y;
    }

    public void setUnactive(){
        this.active = false;
    }
    /*
     * getRotation:  Returns the current Rotations of the Piece
     */
    public Rotation getRotation(){
        return this.rotations[this.currentRotation];
    }

    public Piece clone(){
        return (Piece)this.clone();
    }

    /*
     * rotate: Rotates the piece.
     *
     */
    public void rotateBack(){
        if(this.currentRotation == this.numberOfRotations -1){
            this.currentRotation = 0;
        }else{
            this.currentRotation++;
        }
    }
    public void rotate(){
        if(this.currentRotation == 0){
            this.currentRotation = numberOfRotations-1;
        }else{
            this.currentRotation--;
        }
    }
    public Coordinates getPieceOne(){
        return this.rotations[currentRotation].getPieceOne();
    }
    
    public Coordinates getPieceTwo(){
        return this.rotations[currentRotation].getPieceTwo();
    }
    
    public Coordinates getPieceThree(){
        return this.rotations[currentRotation].getPieceThree();
    }
}
